package com.itheima.web.vo;

/**
 * 同意返回的数据类型
 */
public class Result {
    // code标识码
    /**
     * 201 标识成功
     * 401 客户端错误
     * 501 服务器异常
     */
    private int code;
    private String msg;
    private Object data;

    public static Result success(){
        return new Result(ResultInfoEnum.CODE_SUCCESS,null);
    }
    public static Result success(Object data){
        return new Result(ResultInfoEnum.CODE_SUCCESS,data);
    }

    public static Result clientError(){
        return new Result(ResultInfoEnum.CODE_CLIENT_PARAM_ERROR,null);
    }
    public static Result clientError(Object data){
        return new Result(ResultInfoEnum.CODE_CLIENT_PARAM_ERROR,data);
    }

    public static Result serverError(){
        return new Result(ResultInfoEnum.CODE_SERVER_UNKNOWN_ERROR,null);
    }
    public static Result serverError(Object data){
        return new Result(ResultInfoEnum.CODE_SERVER_UNKNOWN_ERROR,data);
    }



    public Result(ResultInfoEnum resultInfoEnum, Object data) {
        this.code = resultInfoEnum.getCode();
        this.msg = resultInfoEnum.getMsg();
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
